package banking;

import java.util.Date;

import com.mysql.jdbc.PreparedStatement;

/*用于处理吞卡业务
* @author 莫东林
* @version 2018/12/5
*/
public class Retain extends BaseOperation{
	
	private String card_no;//被吞卡号
	private int state;//状态 0未处理 1已处理
	private Date time;//吞卡时间
	private Date dispose_time;//处理时间
	private String atm_id;//对应ATM编号
	
	
	/**
	 * 吞卡
	 * @return
	 */
	@SuppressWarnings("deprecation")
	public static boolean retain(String card_no) {
		sql = "insert into retain(card_no, state, time) values(?,?,?)";
			try {
				stmt = (PreparedStatement) handler.getStmt(sql);
				stmt.setString(1, card_no);
				stmt.setInt(2, 0);
				stmt.setString(3, new Date().toLocaleString());
				stmt.execute();
				return true;
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return false;

	}
	
	/**
	 * 根据卡号查询是否被吞卡未处理的
	 * @return true被吞 false没有被吞
	 */
	public static boolean checkRetain(String card_no){
		sql = "select * from retain where card_no = ?";
		try {
			stmt = (PreparedStatement) handler.getStmt(sql);
			stmt.setString(1, card_no);
			rs = stmt.executeQuery();
			//结果为空或者state=1说明卡状态正常
			System.out.println(rs.toString());
			if(!rs.next()){
				return false;
			}
			/*if(rs.next()){
				if(rs.getInt("state") == 1){
					System.out.println(rs.getInt("state"));
					return false;
				}
			}*/
		} catch (Exception e) {
			// TODO: handle exception
		}
		return true;
	}
	
	
	public String getCard_no() {
		return card_no;
	}
	public void setCard_no(String card_no) {
		this.card_no = card_no;
	}
	public int getState() {
		return state;
	}
	public void setState(int state) {
		this.state = state;
	}
	public Date getTime() {
		return time;
	}
	public void setTime(Date time) {
		this.time = time;
	}
	public Date getDispose_time() {
		return dispose_time;
	}
	public void setDispose_time(Date dispose_time) {
		this.dispose_time = dispose_time;
	}
	public String getAtm_id() {
		return atm_id;
	}
	public void setAtm_id(String atm_id) {
		this.atm_id = atm_id;
	}
	
	
}
